package com.hutu.erp.catalog.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hutu.erp.catalog.domain.SpecificationMapping;
import com.hutu.erp.catalog.service.ISpecificationMappingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品参数值Controller
 * 
 * @author ruoyi
 * @date 2021-05-24
 */
@RestController
@RequestMapping("/catalog/specification_mapping")
public class SpecificationMappingController extends BaseController
{
    @Autowired
    private ISpecificationMappingService specificationMappingService;

    /**
     * 查询商品参数值列表
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_mapping:list')")
    @GetMapping("/list")
    public TableDataInfo list(SpecificationMapping specificationMapping)
    {
        startPage();
        List<SpecificationMapping> list = specificationMappingService.selectSpecificationMappingList(specificationMapping);
        return getDataTable(list);
    }

    /**
     * 导出商品参数值列表
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_mapping:export')")
    @Log(title = "商品参数值", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SpecificationMapping specificationMapping)
    {
        List<SpecificationMapping> list = specificationMappingService.selectSpecificationMappingList(specificationMapping);
        ExcelUtil<SpecificationMapping> util = new ExcelUtil<SpecificationMapping>(SpecificationMapping.class);
        return util.exportExcel(list, "商品参数值数据");
    }

    /**
     * 获取商品参数值详细信息
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_mapping:query')")
    @GetMapping(value = "/{mappingId}")
    public AjaxResult getInfo(@PathVariable("mappingId") Long mappingId)
    {
        return AjaxResult.success(specificationMappingService.selectSpecificationMappingById(mappingId));
    }

    /**
     * 新增商品参数值
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_mapping:add')")
    @Log(title = "商品参数值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpecificationMapping specificationMapping)
    {
        return toAjax(specificationMappingService.insertSpecificationMapping(specificationMapping));
    }

    /**
     * 修改商品参数值
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_mapping:edit')")
    @Log(title = "商品参数值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpecificationMapping specificationMapping)
    {
        return toAjax(specificationMappingService.updateSpecificationMapping(specificationMapping));
    }

    /**
     * 删除商品参数值
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_mapping:remove')")
    @Log(title = "商品参数值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mappingIds}")
    public AjaxResult remove(@PathVariable Long[] mappingIds)
    {
        return toAjax(specificationMappingService.deleteSpecificationMappingByIds(mappingIds));
    }
}
